#!/bin/bash

source head.sh





echo " 
<h1>成绩信息表</h1>  
  
<table>  
    <tr>  
        <th>班级</th>  
        <th>学生</th>  
        <th>考试</th> 
        <th>科目</th>  
        <th>成绩</th>

    </tr> "

cntsql="select count(1) from jx_score  join jx_stu on jx_score.stu_id=jx_stu.id  join jx_test on jx_score.test_id=jx_test.id  join jx_subject on jx_score.subject_id =jx_subject.id  join jx_class on jx_stu.class_id=jx_class.id;"

datasql=" select jx_class.name as 班级,jx_stu.name as 学生 ,jx_test.name as 考试, jx_subject.name as 科目 , jx_score.score from jx_score  join jx_stu on jx_score.stu_id=jx_stu.id  join jx_test on jx_score.test_id=jx_test.id  join jx_subject on jx_score.subject_id =jx_subject.id  join jx_class on jx_stu.class_id=jx_class.id;"


count=$(mysql -h10.10.10.81 -ujxadmin -p123456 jxcms -e "$cntsql " | grep -v count)

for ((i=1;i<=$count;i++));do
stu=$(mysql -h10.10.10.81 -ujxadmin -p123456 jxcms -e "$datasql" |grep -v score |sed -n $i"p")
className=$(echo $stu | awk -F " " '{print $1}')
stuName=$(echo $stu | awk -F " " '{print $2}')
testName=$(echo $stu | awk -F " " '{print $3}')
subjectName=$(echo $stu | awk -F " " '{print $4}')
score=$(echo $stu | awk -F " " '{print $5}')

echo " 
   <tr>  
        <td>$className</td>  
        <td>$stuName</td>  
        <td>$testName</td>  
        <td>$subjectName</td> 
        <td>$score</td>
    </tr> "
done  
echo "   <!-- 可以在这里继续添加更多学生信息 -->  "
source foot.sh

